/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evolve.webbot.database;
import  java.sql.SQLException;
import  java.sql.ResultSet;
import  java.sql.PreparedStatement;
import  com.evolve.webbot.bean.LiverpoolMntBean;

/**
 *
 * @author DarthAE
 */
public class Query 
{
    public Query(){}
    
    public int existeRegistroLiverpoolMes(LiverpoolMntBean liverpool,
                                          String fechaBusqueda,
                                          Conexion con)
    {
        int    existeRegistro  = 0;
        ResultSet         rs   = null;
        PreparedStatement stmt = null;
        
        double ventaMesActual     = 0;
        double ventaMesAnterior   = 0;
        double ventaAcumuladaAnio = 0;
        int    invMesActual       = 0;
        int    onOrder            = 0;
        
        try{
             ventaMesActual     = Double.parseDouble(liverpool.getVentaMesActual());
             ventaMesAnterior   = Double.parseDouble(liverpool.getVentaMesAnterior());
             ventaAcumuladaAnio = Double.parseDouble(liverpool.getVentaAcumuladaAnio());
             invMesActual       = Integer.parseInt(liverpool.getInventarioMesActual());
             onOrder            = Integer.parseInt(liverpool.getOnOrder());
             
           }catch(Exception e){}
        
        String query = "select count(1) count "+
                       "from   liverpool_vm_articulo "+
                       "where  modelo   ='"+liverpool.getModelo()+"' "+
                       "and    ean_upc  ='"+liverpool.getEanUpc()+"' "+
                       "and    articulo ='"+liverpool.getArticulo()+"' "+
                       "and    descripcion  ='"+liverpool.getDescripcion()+"' "+
                       "and    temporada    ='"+liverpool.getTemporada()+"' "+
                       "and    vta_mes_act  ="+ventaMesActual+" "+
                       "and    vta_mes_ant  ="+ventaMesAnterior+" "+
                       "and    vta_acu_anio ="+ventaAcumuladaAnio+" "+
                       "and    inv_mes_act  ="+invMesActual+" "+
                       "and    on_order     ="+onOrder+" "+
                       "and    dte_dwd = '"+fechaBusqueda+"' ";
        
        try{
              stmt = con.getConnection().prepareStatement(query);
              rs   = stmt.executeQuery();
            
              while(rs.next())
              {
                 existeRegistro=rs.getInt("count");   
              }
            
           }catch(SQLException sqlex){System.out.println(sqlex);}
        
        return existeRegistro;
    }
}
